﻿using System.Net;
using System.Net.Mail;
using PCC.Notification;

namespace PCC.App.Notification
{
    public class NotificationFactory
    {
        public static INotificationSystem _system = new NotificationSystem();

        public static INotificationContext GetContext(string key, IRecipient recipient)
        {
            return new NotificationContext(key, _system, recipient);
        }

        public static void Send(INotificationContext notificationContext)
        {
            SmtpClient client =
                new SmtpClient(notificationContext.NotificationSystem.SmtpHost,
                               notificationContext.NotificationSystem.SmtpPort)
                    {
                        Credentials =
                            new NetworkCredential(
                            notificationContext.NotificationSystem.SmtpUsername,
                            notificationContext.NotificationSystem.SmtpPassword),
                        EnableSsl = true
                    };


            client.Send(notificationContext.NotificationSystem.SmtpFromEMail,
                        notificationContext.Recipient.EMail,
                        notificationContext.Notification.Subject,
                        notificationContext.Notification.Body
                );

        }

        public static void Send(string key, IRecipient recipient)
        {
            Send(GetContext(key, recipient));
        }
    }
}